package com.zy.pro.shop.web;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zy.core.model.PageView;
import com.zy.core.web.BaseController;
import com.zy.pro.shop.model.Cases;
import com.zy.pro.shop.model.Pic;
import com.zy.pro.shop.service.CasesService;
import com.zy.pro.shop.web.form.CasesSearchForm;
/**
 * 案例管理控制器
 *
 */
@Controller
@RequestMapping("/control/shop/casesController")
public class CasesController extends BaseController {

	private static final Logger logger = Logger.getLogger(CasesController.class);
	
	/**
	 * 案例管理服务类
	 */
	@Resource(name = "casesServiceImpl")
	private CasesService casesService;
	
	/**
	 * 列出案例管理
	 *//*
	@RequestMapping("/list")
	public String list(CasesSearchForm form, ModelMap map) {
		try {
			//设置查询排序
			//TODO eg:form.getOrderby().put("id", "asc");
			form.getOrderby().put("caseCreateTime", "desc");
			
			//创建页面对象
			PageView<Cases> pageView = new PageView<Cases>(12, form.getPage());
			form.setFirstResult(pageView.getFirstResult());
			form.setMaxResult(pageView.getMaxresult());
			pageView.setQueryResult(casesService.getData(form));
			map.addAttribute("pageView", pageView);
			map.addAttribute("form", form);
			//TODO 转发页面
			return "/control/shop/casesList";
		} catch(Exception e){
			logger.error(e);
			return "error";
		}
	}
	
	*//**
	 * 显示添加案例管理
	 *//*
	@RequestMapping("/displayAdd")
	public String displayAdd(Cases cases, ModelMap map) {
		try {
			//TODO 加载显示页面数据
			//判断添加/编辑的操作状态
			map.addAttribute("operateStatus", "add");
			map.addAttribute("cases", cases);
			
			//TODO 转发页面
			return "control/shop/editCases";
		} catch(Exception e){
			logger.error(e);
			return "error";
		}
	}
	
	*//**
	 * 添加案例管理
	 *//*
	@RequestMapping("/add")
	public String add(Cases cases,String picPath0,String picPath1,String picPath2,String picPath3,
			String picPath4,String picPath5,String picPath6,String picPath7,String picPath8,
			String picPath9,ModelMap map, HttpServletRequest request) {
		try {
			//TODO 设置cases  eg:主键信息
			
			casesService.addCasesAndPics(cases,picPath0, picPath1, picPath2, picPath3,
					 picPath4, picPath5, picPath6, picPath7, picPath8, picPath9, request, logger);
			
			CasesSearchForm form = new CasesSearchForm();
			form.setCaseShopId(cases.getCaseShopId());
			//casesService.save(cases);
			return list(form, map);
		} catch(Exception e){
			logger.error(e);
			return "error";
		}
	}
	
	*//**
	 * 显示编辑案例管理
	 *//*
	@RequestMapping("/displayEdit")
	public String displayEdit(CasesSearchForm form, ModelMap map) {
		try {
			//TODO 查询对象
			//eg:Cases cases = casesService.find(form.getId());
			//eg:map.addAttribute("entity", cases);
//			Cases cases = casesService.find(form.getCaseId());
			Cases cases = casesService.findCasesAndAllPics(form.getCaseId());
			map.addAttribute("operateStatus", "edit");
			map.addAttribute("cases", cases);
			
			//TODO 转发页面
			return "control/shop/editCases";
		} catch (Exception e) {
			logger.error(e);
			return "error";
		}
	}
	
	*//**
	 * 显示编辑案例管理
	 *//*
	@RequestMapping("/displayCasesDetail")
	public String displayCasesDetail(CasesSearchForm form, ModelMap map) {
		try {
			//TODO 查询对象
			//eg:Cases cases = casesService.find(form.getId());
			//eg:map.addAttribute("entity", cases);
			Cases cases = casesService.find(form.getCaseId());
			map.addAttribute("operateStatus", "edit");
			map.addAttribute("cases", cases);
			
			//TODO 转发页面
			return "control/shop/casesDetail";
		} catch (Exception e) {
			logger.error(e);
			return "error";
		}
	}
	
	*//**
	 * 编辑案例管理
	 *//*
	@RequestMapping("/edit")
	public String edit(Cases cases,String picPath0,String picPath1,String picPath2,String picPath3,
			String picPath4,String picPath5,String picPath6,String picPath7,String picPath8,
			String picPath9,ModelMap map, HttpServletRequest request) {
		try {
			//TODO:处理案例管理
			casesService.editCasesAndPics(cases,picPath0, picPath1, picPath2, picPath3,
					 picPath4, picPath5, picPath6, picPath7, picPath8, picPath9, request, logger);
			CasesSearchForm form = new CasesSearchForm();
			form.setCaseShopId(cases.getCaseShopId());
			return list(form, map);
		} catch (Exception e) {
			logger.error(e);
			return "error";
		}
		
	}

	*//**
	 * 删除单个案例管理
	 *//*
	@RequestMapping("/deletecases")
	public String delete(CasesSearchForm form, ModelMap map) {
		try {
			//TODO  eg:casesService.delete(form.getId());
			
			return list(form, map);
		} catch (Exception e) {
			logger.error(e);
			return "error";
		}
	}
	
	*//**
	 * 批量删除案例管理
	 *//*
	@RequestMapping("/batchDelete")
	public String deletes(CasesSearchForm form, ModelMap map) {
		try {
//			TODO  eg:casesService.batchDelete(form.getIds());
			
			return list(form, map);
		} catch (Exception e) {
			logger.error(e);
			return "error";
		}
	}*/
}
